#include "control.h"
#include"steppermotor.h"
#include"light.h" 
extern unsigned char curLayer=1;  

void Delay_ms(int ms)                //ms延迟函数，ms=1时，大约延时1ms
{
	int i,j;
	for(i=ms;i>0;i--)
		for(j=110;j>0;j--);
}

void Up(unsigned char layer)//电梯上行（步进电机正转）
{
	int i,j; 
		ShowShumaguan(1,7);
		for(i=1;i<=layer-curLayer;i++)
		{
			for(j=0;j<5;j++)MoveMotor(0);
			ShowShumaguan(4,curLayer+i);
		}
		curLayer=layer;
}

void Down(unsigned char layer)//电梯下行（步进电机反转）
{
	int i,j;
		ShowShumaguan(1,13);
		for(i=1;i<=curLayer-layer;i++)
		{
			for(j=0;j<5;j++)MoveMotor(1);
			ShowShumaguan(4,curLayer-i);
		}
		curLayer=layer; 
}

void Stop()//电梯停止（步进电机停止
{ 
	ShowShumaguan(1,10);
}

void PushButton_Outside(unsigned char key){//在某层楼按键（flag：（0）上/（1）下；layer：层数）
    if(key<4){
        P1^=(1<<(key<<1)); //第一行键盘，对应led位为键码*2
    }else if(key<8){
        P1^=(1<<(((key^4)<<1)|1)); //第二行键盘，对应led位为（键码-4）*2+1
    }
}

void PushButton_Inside(unsigned char layer)//在电梯内部按楼层键
{
	P2^=(1<<layer); //对应led位即层数
}

void OpenDoor()//电梯开门
{
 
		ShowShumaguan(2,0);
 
}

void CloseDoor()//电梯关门
{
 
		ShowShumaguan(2,12);
 
}